package com.hxmall.appclient.controller.product;

import com.hxmall.appclient.client.ProductFeignClient;
import com.hxmall.commonservice.common.constants.feign.FeignApplicationName;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Author Eirunye
 * Created by on 2018/9/10.
 * Describe 商品API
 */
@Api(value = "product",tags = "商品API、商品列表、商品分类")
@RestController
public class ProductController {
    private final Logger logger = LoggerFactory.getLogger(ProductController.class);


    @Autowired
    ProductFeignClient productFeignClient;

    @Autowired
    RestTemplate restTemplate;

    @ApiOperation(value = "通过Product-service获取数据测试",notes = "Feign方式实现负载均衡")
    @RequestMapping(value = "/get/product")
    public String getProductTest() {
        logger.info("Feign请求数据");
        return productFeignClient.getProductTest();
    }

    @ApiOperation(value = "通过Product-service获取数据测试",notes = "ribbon方式实现负载均衡")
    @RequestMapping(value = "get/ribbon")
    public String getRibbonProductTest(){
        return restTemplate.getForObject("http://"+ FeignApplicationName.ApplicationName.PRODUCT_SERVICE+"/get/product",String.class);
    }

}
